//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.project.smarthome.common.widget.dialog;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.graphics.NinePatch;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.NinePatchDrawable;
import android.os.Build.VERSION;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;

import static android.content.Context.LAYOUT_INFLATER_SERVICE;

public class DrawableUtil {
    private static HashMap<String, Drawable> e = new HashMap();
    private static HashMap<String, Drawable> f = new HashMap();
    public static int a = 3;
    public static int b = 4;
    public static int c = 7;
    public static int d = 8;

    private static InputStream b(Context var0, String var1) throws IOException {
        InputStream var2 = var0.getAssets().open(var1);
        return var2;
    }

    public static View a(Context var0, String var1, ViewGroup var2) throws Exception {
        String var3 = "assets/iflytek/" + var1 + ".xml";
        XmlResourceParser var4 = var0.getAssets().openXmlResourceParser(var3);
        LayoutInflater var5 = (LayoutInflater)var0.getSystemService(LAYOUT_INFLATER_SERVICE);
        return var5.inflate(var4, var2);
    }

    public static synchronized Drawable a(Context var0, String var1) throws Exception {
        Drawable var2 = (Drawable)e.get(var1);
        if(var2 == null) {
            var2 = c(var0, var1);
            e.put(var1, var2);
        }

        return var2;
    }

    private static Drawable c(Context var0, String var1) throws Exception {
        InputStream var2 = b(var0, "iflytek/" + var1 + ".png");
        TypedValue var3 = new TypedValue();
        var3.density = 240;
        Drawable var4 = null;
        if(VERSION.SDK_INT > a) {
            var4 = getDrawable(var0.getResources(), var3, var2, var1, (Options)null);
        } else {
            var4 = Drawable.createFromResourceStream(var0.getResources(), var3, var2, var1);
        }

        if(var2 != null) {
            var2.close();
        }

        return var4;
    }
    private static Drawable getDrawable(Resources var0, TypedValue var1, InputStream var2, String var3, Options var4) {
        if(var2 == null) {
            return null;
        } else {
            Rect var5 = new Rect();
            if(var4 == null) {
                var4 = new Options();
            }

            Bitmap var6 = a(var0, var1, var2, var5, var4);
            if(var6 == null) {
                return null;
            } else {
                byte[] var7 = var6.getNinePatchChunk();
                if(var7 == null || !NinePatch.isNinePatchChunk(var7)) {
                    var7 = null;
                    var5 = null;
                }

                Drawable var8 = a(var0, var6, var7, var5, var3);
                return var8;
            }
        }
    }
    private static Drawable a(Resources var0, Bitmap var1, byte[] var2, Rect var3, String var4) {
        return (Drawable)(var2 != null?new NinePatchDrawable(var0, var1, var2, var3, var4):new BitmapDrawable(var0, var1));
    }
    private static Bitmap a(Resources var0, TypedValue var1, InputStream var2, Rect var3, Options var4) {
        if(var4 == null) {
            var4 = new Options();
        }

        if(var4.inDensity == 0 && var1 != null) {
            int var5 = var1.density;
            if(var5 == 0) {
                var4.inDensity = 160;
            } else if(var5 != '\uffff') {
                var4.inDensity = var5;
            }
        }

        if(var4.inTargetDensity == 0 && var0 != null) {
            var4.inTargetDensity = var0.getDisplayMetrics().densityDpi;
        }

        return BitmapFactory.decodeStream(var2, var3, var4);
    }
}
